//
//  YYEScoreView1.m
//  YuYingEDU
//
//  Created by zl on 2018/4/2.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYEScoreView1.h"
#import "UILabel+WLAttributedString.h"


@implementation YYEScoreView1

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5];
        
        UIImageView *imgView1 = [UIImageView imgViewWithframe:CGRectZero icon:@"弹窗2"];
//        imgView1.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:imgView1];
        imgView1.userInteractionEnabled = YES;
        self.imgView1 = imgView1;
        
        
        UILabel *remindLab = [UILabel labelWithframe:CGRectZero text:@"" font:[UIFont systemFontOfSize:15] textAlignment:NSTextAlignmentLeft textColor:@"#000000"];
        [self.imgView1 addSubview:remindLab];
        self.remindLab = remindLab;
        remindLab.numberOfLines = 0;
        
        UILabel *remindLab1 = [UILabel labelWithframe:CGRectZero text:@"" font:[UIFont systemFontOfSize:15] textAlignment:NSTextAlignmentLeft textColor:@"#000000"];
        [self.imgView1 addSubview:remindLab1];
        self.remindLab1 = remindLab1;
        remindLab1.numberOfLines = 0;
        
        UIButton *cancelBtn = [UIButton buttonWithframe:CGRectZero text:@"" font:nil textColor:@"#333333" backgroundColor:nil normal:@"关闭2" selected:nil];
        [self addSubview:cancelBtn];
        [cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
        self.cancelBtn = cancelBtn;
        
    }
    return self;
}

- (void)setText1:(NSString *)text1 text2:(NSString *)text2;
{
    
//    remindText = @"您的试卷已批改，\n批改结果如下：\n总分：100\n单选：20    多选：30\n判断：10    填空：40\n简答：40";

    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:8.0f];
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text1];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text1 length])];
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15.f], NSParagraphStyleAttributeName:paragraphStyle};
    CGFloat questionLabelH = [text1 boundingRectWithSize:CGSizeMake(250-102, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size.height;
    
    self.remindLab.attributedText = attributedString;
    
    // 后面加才有效
    self.remindLab.textAlignment = NSTextAlignmentCenter;
    
    [self.remindLab wl_changeColorWithTextColor:[UIColor colorWithHexString:@"#f5791d"] changeText:@"100"];
    
    //////////////////////////
    NSMutableAttributedString *attributedString2 = [[NSMutableAttributedString alloc] initWithString:text2];
    [attributedString2 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text2 length])];
    NSDictionary *dic2 = @{NSFontAttributeName:[UIFont systemFontOfSize:15.f], NSParagraphStyleAttributeName:paragraphStyle};
    CGFloat questionLabelH2 = [text2 boundingRectWithSize:CGSizeMake(250-102, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic2 context:nil].size.height;

    self.remindLab1.attributedText = attributedString2;
    
    // 后面加才有效
    self.remindLab1.textAlignment = NSTextAlignmentLeft;
    
    [self.remindLab1 wl_changeColorWithTextColor:[UIColor colorWithHexString:@"#f5791d"] changeText:@"20"];
    [self.remindLab1 wl_changeColorWithTextColor:[UIColor colorWithHexString:@"#f5791d"] changeText:@"30"];
    [self.remindLab1 wl_changeColorWithTextColor:[UIColor colorWithHexString:@"#f5791d"] changeText:@"10"];
    [self.remindLab1 wl_changeColorWithTextColor:[UIColor colorWithHexString:@"#f5791d"] changeText:@"50"];
    [self.remindLab1 wl_changeColorWithTextColor:[UIColor colorWithHexString:@"#f5791d"] changeText:@"40"];

//    self.imgView1.frame = CGRectMake((self.jc_width-250)/2, (self.jc_height-(94+22+questionLabelH))/2, 250, 94+22+questionLabelH);
    self.imgView1.frame = CGRectMake((self.jc_width-250)/2, (self.jc_height-279)/2, 250, 279);

    self.remindLab.frame = CGRectMake(51, 94, self.imgView1.jc_width-102, questionLabelH);
    self.remindLab1.frame = CGRectMake(self.remindLab.jc_x, self.remindLab.jc_bottom+8, self.remindLab.jc_width, questionLabelH2);

    self.cancelBtn.frame = CGRectMake(self.imgView1.jc_right-17, self.imgView1.jc_y+11, 35, 35);


}

- (void)cancelAction
{
    [self removeFromSuperview];
}

@end
